/*
 * solver.h
 *
 *  Created on: 2011-08-22
 *      Author: Graham
 */

#ifndef SOLVER_H_
#define SOLVER_H_

#include <string>
#include "cipher.h"
#include "key.h"
#include "dictionary.h"

using namespace std;

class Solver{
public:
	Key bestKey; //Key class containing the key which has been determined best
	
	Solver(Dictionary*); //Constructor takes argument of pointer to pre-created Dictionary instance
	int solve(Key*, Cipher*); //Function to import user Key and a Cipher, subdivide the cipher into words, and initate the solver class using whatever algorithm seems appropriate.
						  	  //Returns integer indicating percentage of words in list matched, or -1 indicating that no satisfactory key could be found, and the value in Solver::bestKey is just the last one generated (or best candidate?).
	
private:
	Key userKey; //Key class containing user input key.  This will be the starting point, and only modified if all else fails.
	char** wordList; //Array of character arrays containing all words in the cipher.
	Dictionary* dict; //Pointer to dictionary instance passed in constructor
        
	void divideCipher(Cipher*); //Function which takes the cipher argument, and divides the cipher text into words, populating the `wordList`
	int recursiveSolve(Key*, char**); //Function which takes the user supplied key, and the word list, and brute forces the gaps based on each word in the list, sequentially.
							 		  //Returns integer indicating success or failure
};

class SolverException{
public:
	SolverException(const string& errorMessage);//constructor takes error message
	string& getMessage();
private:
	string message;
};

#endif /* SOLVER_H_ */
